package com.mayuhao.homework.chapter3.homework3四1_加法计算;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.mayuhao.homework.R;

public class AdditionActivity extends AppCompatActivity {
    private EditText etFirstNum;
    private EditText etSecondNum;
    private TextView tvTotal;

    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_addition);

        etFirstNum = findViewById(R.id.et_first_num);
        etSecondNum = findViewById(R.id.et_second_num);
        tvTotal = findViewById(R.id.tv_total);

    }

    public void calculator_total(View view) {
        int a = Integer.parseInt(etFirstNum.getText().toString());
        int b = Integer.parseInt(etSecondNum.getText().toString());
        int total = sum(a, b);

        tvTotal.setText(total+"");

    }

    public int sum(int a, int b) {
        return a + b;
    }
}